﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Amrta.Export.Excel;
using CommunitySystem.Assert;
using CommunitySystem.Ctrls;
using CommunitySystem.PageView;
using CommunitySystem.PageView.EmpBasicManager;
using CommunitySystem.PublicOfficialSelectionService;
using CommunitySystem.Views;
using EHR.Common;
using org.in2bits.MyXls;

namespace CommunitySystem
{
    public partial class PublicOfficialRecordControl : AsyncCtrl, IReturnListenerc
    {
        #region IReturnListenerc 成员
        public void BeginReturn()
        {
            Load(OrgID);
        }
        #endregion
        public NavMoveSwitch Nav { get; set; }
        private EmpbasicService.EmpBasicServiceClient Client = new EmpbasicService.EmpBasicServiceClient();
        private PublicOfficialSelectionService.PublicOfficialSelectionServiceClient Client1 =
            new PublicOfficialSelectionService.PublicOfficialSelectionServiceClient();
        private ObservableCollection<PublicOfficialSelectionService.PublicOfficialRecordModel> selectedempmodel =
            new ObservableCollection<PublicOfficialSelectionService.PublicOfficialRecordModel>();
        private SystemService.SystemServiceClient _SystemClient = null;
        private int ExamID = 0;
        public PublicOfficialRecordControl()
        {
            InitializeComponent();
            Client.GetOrgForHRModelCompleted += new EventHandler<EmpbasicService.GetOrgForHRModelCompletedEventArgs>(Client_GetOrgForHRModelCompleted);
            Client.GetOrgForHRModelAsync(0);
            for (int i = DateTime.Today.Year; i > DateTime.Today.Year - 10; i--)
            {
                ComboBoxItem cbi = new ComboBoxItem();
                cbi.Content = i.ToString();
                cbi.Tag = i;
                nian.Items.Add(cbi);
            }
            _SystemClient = new SystemService.SystemServiceClient();
            _SystemClient.GetRegisterSysteLoginTimeCompleted += new EventHandler<SystemService.GetRegisterSysteLoginTimeCompletedEventArgs>(_SystemClient_GetRegisterSysteLoginTimeCompleted);
            _SystemClient.GetRegisterSysteLoginTimeAsync(Session.LoginUser.LoginName);
            nian.SelectedIndex = 0;
            Client1.GetPublicOfficialInfo1Completed += new EventHandler<GetPublicOfficialInfo1CompletedEventArgs>(Client1_GetPublicOfficialInfo1Completed);
            Client1.GetPublicOfficialInfo1Async(1, DateTime.Today.Year - nian.SelectedIndex);
            Load(OrgID);
        }

        /// <summary>
        /// 获得报名系统登录信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _SystemClient_GetRegisterSysteLoginTimeCompleted(object sender, SystemService.GetRegisterSysteLoginTimeCompletedEventArgs e)
        {
            var list = e.Result;
            if (list.Count > 0)
            {
                todaycount.Visibility = System.Windows.Visibility.Visible;
                totalcount.Visibility = System.Windows.Visibility.Visible;
                todaycount.Text = "今日登录次数:" + list[0];
                totalcount.Text = "总计登录次数:" + list[1];
            }
        }

        void Client1_GetPublicOfficialInfo1Completed(object sender, GetPublicOfficialInfo1CompletedEventArgs e)
        {
            biaoti.ItemsSource = e.Result;
            biaoti.SelectedIndex = 0;
        }
        public void Load(int orgid)
        {
            Client1.ChaKanShiFouDouShenHeBaoMingRenCompleted +=
                new EventHandler<PublicOfficialSelectionService.ChaKanShiFouDouShenHeBaoMingRenCompletedEventArgs>(Client1_ChaKanShiFouDouShenHeBaoMingRenCompleted);
            Client1.ChaKanShiFouDouShenHeBaoMingRenAsync(DateTime.Today.Year - nian.SelectedIndex, islock);
            Client1.GetPublicOfficialRecordCountCompleted +=
                new EventHandler<PublicOfficialSelectionService.GetPublicOfficialRecordCountCompletedEventArgs>(Client1_GetPublicOfficialRecordCountCompleted);
            Client1.GetPublicOfficialRecordCountAsync(orgid, DateTime.Today.Year - nian.SelectedIndex, islock, ExamID);

            Client1.GetPublicOfficialRecordCompleted +=
                new EventHandler<PublicOfficialSelectionService.GetPublicOfficialRecordCompletedEventArgs>(Client1_GetPublicOfficialRecordCompleted);
            Client1.GetPublicOfficialRecordAsync(orgid, 0, 20, DateTime.Today.Year - nian.SelectedIndex, islock, ExamID);
        }
        void gangwei_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (((ComboBox)sender).SelectedItem != null)
            ExamID = ((CommunitySystem.PublicOfficialSelectionService.PublicOfficialInfo)((((ComboBox)sender).SelectedItem))).ID;
        }

        void Client1_ChaKanShiFouDouShenHeBaoMingRenCompleted(object sender, PublicOfficialSelectionService.ChaKanShiFouDouShenHeBaoMingRenCompletedEventArgs e)
        {
            if (e.Result != null)
                tiaomu.Text = "剩余" + e.Result + "条报名信息没有审核";
            else tiaomu.Text = "没有待审核的报名信息";
        }
        public ObservableCollection<PublicOfficialSelectionService.PublicOfficialRecordModel> empmodel =
            new ObservableCollection<PublicOfficialSelectionService.PublicOfficialRecordModel>();
        void Client1_GetPublicOfficialRecordCompleted(object sender, PublicOfficialSelectionService.GetPublicOfficialRecordCompletedEventArgs e)
        {
            foreach (PublicOfficialSelectionService.PublicOfficialRecordModel i in e.Result)
            {
                if (empmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                {
                    empmodel.Add(i);
                }
            }
            foreach (PublicOfficialSelectionService.PublicOfficialRecordModel i in selectedempmodel)
            {
                if (e.Result.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == true)
                {
                    e.Result.Where(p => p.ID == i.ID).FirstOrDefault().IsSelected = true;
                }
            }
            DGRole.ItemsSource = e.Result;
            tempforall = e.Result;
        }
        private string islock = "0";
        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            islock = "1";
            Client1.GetPublicOfficialInfo1Completed += new EventHandler<GetPublicOfficialInfo1CompletedEventArgs>(Client1_GetPublicOfficialInfo1Completed);
            Client1.GetPublicOfficialInfo1Async(0, DateTime.Today.Year - nian.SelectedIndex);
        }

        private void chkHiddenCols_Unchecked(object sender, RoutedEventArgs e)
        {
            islock = "0";
            Client1.GetPublicOfficialInfo1Completed += new EventHandler<GetPublicOfficialInfo1CompletedEventArgs>(Client1_GetPublicOfficialInfo1Completed);
            Client1.GetPublicOfficialInfo1Async(1, DateTime.Today.Year - nian.SelectedIndex);
        }
        void Client1_GetPublicOfficialRecordCountCompleted(object sender, PublicOfficialSelectionService.GetPublicOfficialRecordCountCompletedEventArgs e)
        {
            int count = e.Result;
            ObservableCollection<int> source = new ObservableCollection<int>();
            for (int i = 0; i < count; i++)
            {
                source.Add(i + 1);

            }
            PagedCollectionView pcv = new PagedCollectionView(source);
            dataPager1.PageSize = 1;
            dataPager1.Source = pcv;
        }
        private void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            CheckBox cb = sender as CheckBox;
            foreach (PublicOfficialSelectionService.PublicOfficialRecordModel p in DGRole.ItemsSource)
            {
                p.IsSelected = (bool)cb.IsChecked;
                //CheckBox cb1 = DGRole.Columns[0].GetCellContent(p) as CheckBox;
                //cb1.IsChecked = p.IsSelected;
                if (p.IsSelected)
                {
                    if (selectedempmodel.Where(i => i.ID == p.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(p);
                    }
                }
                else
                {
                    if (selectedempmodel.Where(i => i.ID == p.ID).FirstOrDefault() != null)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(i => i.ID == p.PublicOfficialRecordID).FirstOrDefault());
                    }
                }
            }


        }

        private void ChaData_Click(object sender, RoutedEventArgs e)
        {
            Client1.ChaKanShiFouDouShenHeBaoMingRenCompleted -=
                new EventHandler<PublicOfficialSelectionService.ChaKanShiFouDouShenHeBaoMingRenCompletedEventArgs>(Client1_ChaKanShiFouDouShenHeBaoMingRenCompleted);
            Client1.ChaKanShiFouDouShenHeBaoMingRenCompleted +=
                new EventHandler<PublicOfficialSelectionService.ChaKanShiFouDouShenHeBaoMingRenCompletedEventArgs>(Client1_ChaKanShiFouDouShenHeBaoMingRenCompleted);
            Client1.ChaKanShiFouDouShenHeBaoMingRenAsync(DateTime.Today.Year - nian.SelectedIndex, islock);
            Client1.GetPublicOfficialRecordCountCompleted -=
                new EventHandler<PublicOfficialSelectionService.GetPublicOfficialRecordCountCompletedEventArgs>(Client1_GetPublicOfficialRecordCountCompleted);
            Client1.GetPublicOfficialRecordCountCompleted +=
                new EventHandler<PublicOfficialSelectionService.GetPublicOfficialRecordCountCompletedEventArgs>(Client1_GetPublicOfficialRecordCountCompleted);
            Client1.GetPublicOfficialRecordCountAsync(OrgID, DateTime.Today.Year - nian.SelectedIndex, islock, ExamID);
            Client1.GetPublicOfficialRecordCompleted -=
                new EventHandler<PublicOfficialSelectionService.GetPublicOfficialRecordCompletedEventArgs>(Client1_GetPublicOfficialRecordCompleted);
            Client1.GetPublicOfficialRecordCompleted +=
                new EventHandler<PublicOfficialSelectionService.GetPublicOfficialRecordCompletedEventArgs>(Client1_GetPublicOfficialRecordCompleted);
            Client1.GetPublicOfficialRecordAsync(OrgID, 0, 20, DateTime.Today.Year - nian.SelectedIndex, islock, ExamID);
        }
        #region treeview
        private int OrgID = 0;
        void Client_GetOrgForHRModelCompleted(object sender, EmpbasicService.GetOrgForHRModelCompletedEventArgs e)
        {
            forumList.Clear();
            foreach (EmpbasicService.OrgForHRModel i in e.Result)
            {
                forumList.Add(i);
            }
            AddTreeNode("全部单位", null);
        }
        ObservableCollection<EmpbasicService.OrgForHRModel> forumList = new ObservableCollection<EmpbasicService.OrgForHRModel>();


        private void AddTreeNode(string type, TreeViewItem treeViewItem)
        {
            List<EmpbasicService.OrgForHRModel> result = (from forumInfo in forumList
                                                          where forumInfo.Type == type
                                                          select forumInfo).ToList<EmpbasicService.OrgForHRModel>();

            if (result.Count > 0)
            {
                foreach (EmpbasicService.OrgForHRModel foruminfo in result)
                {
                    TreeViewItem objTreeNode = new TreeViewItem();
                    CheckBox cb = new CheckBox();
                    cb.Content = foruminfo.Name;
                    cb.Tag = objTreeNode;
                    cb.DataContext = foruminfo;
                    //sp.Children.Add(cb);
                    cb.Click += new RoutedEventHandler(cb_Checked);
                    objTreeNode.Header = cb;
                    if ((objTreeNode.Header as CheckBox).Content.ToString() == "组织机构") objTreeNode.IsExpanded = true;
                    //添加根节点
                    if (treeViewItem == null)
                    {
                        TreeOfLife.Items.Add(objTreeNode);
                    }
                    else
                    {
                        treeViewItem.Items.Add(objTreeNode);
                    }
                    AddTreeNode(foruminfo.Name, objTreeNode);
                }
            }
        }
        void cb_Checked(object sender, RoutedEventArgs e)
        {
            CheckBox cb = sender as CheckBox;
            EmpbasicService.OrgForHRModel rm = cb.DataContext as EmpbasicService.OrgForHRModel;
            if (cb.IsChecked == true)
            {
                if (orgids != null)
                {
                    OrgID = Convert.ToInt32(((EmpbasicService.OrgForHRModel)cb.DataContext).ID);
                    Load(OrgID);
                }
                else orgids.Add(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString());
                CheckChildItem(cb.Tag as TreeViewItem);
            }
            else
            {
                if (orgids != null)
                {
                    if (orgids.Contains(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString()))
                        orgids.Remove(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString());
                }
                UnCheckChildItem(cb.Tag as TreeViewItem);
            }
        }
        void CheckParentItem(TreeViewItem item)
        {
            TreeViewItem tvi = item.GetParentTreeViewItem();
            if (tvi != null)
            {
                CheckBox cb = tvi.Header as CheckBox;
                cb.IsChecked = true;
                CheckParentItem(tvi);
            }
        }
        public List<string> orgids = new List<string>();
        void CheckChildItem(TreeViewItem item)
        {
            foreach (TreeViewItem tvi in item.Items)
            {
                if (tvi != null)
                {
                    CheckBox cb = tvi.Header as CheckBox;
                    cb.IsChecked = true;
                    if (!orgids.Contains(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString()))
                        orgids.Add(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString());
                    CheckChildItem(tvi);
                }
            }
        }
        void UnCheckChildItem(TreeViewItem item)
        {
            foreach (TreeViewItem tvi in item.Items)
            {
                if (tvi != null)
                {
                    CheckBox cb = tvi.Header as CheckBox;
                    cb.IsChecked = false;
                    if (orgids.Contains(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString()))
                        orgids.Remove(((EmpbasicService.OrgForHRModel)cb.DataContext).ID.ToString());
                    UnCheckChildItem(tvi);
                }
            }
        }
        #endregion
        #region 左右拖动的条
        private GridLength _lastColLeftLength;
        private GridLength _lastColRightLength;
        private void GridSpliteTo_ToLeft(object sender, EventArgs e)
        {
            //已经到最左边，直接返回
            if (colLeft.Width.Value == 0.0)
            {
                return;
            }

            //
            if (colRight.Width.Value == 0)
            {
                colLeft.Width = _lastColLeftLength;
                colRight.Width = _lastColRightLength;
            }
            else
            {
                _lastColLeftLength = colLeft.Width;
                _lastColRightLength = colRight.Width;

                colLeft.Width = new GridLength(0);
                colRight.Width = new GridLength(150, GridUnitType.Star);
            }
        }

        private void GridSpliteTo_ToRight(object sender, EventArgs e)
        {
            if (colRight.Width.Value == 0)
            {
                return;
            }

            if (colLeft.Width.Value == 0)
            {
                colLeft.Width = _lastColLeftLength;
                colRight.Width = _lastColRightLength;
            }
            else
            {
                _lastColLeftLength = colLeft.Width;
                _lastColRightLength = colRight.Width;

                colRight.Width = new GridLength(0);
                colLeft.Width = new GridLength(300, GridUnitType.Star);
            }
        }
        #endregion
        #region 翻页
        private void dataPager1_PageIndexChanged(object sender, EventArgs e)
        {
            int index = dataPager1.PageIndex;

            if (DGRole.ItemsSource != null)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialRecordModel i in (ObservableCollection<PublicOfficialSelectionService.PublicOfficialRecordModel>)DGRole.ItemsSource)
                {
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            Client1.GetPublicOfficialRecordCompleted -=
                new EventHandler<PublicOfficialSelectionService.GetPublicOfficialRecordCompletedEventArgs>(Client1_GetPublicOfficialRecordCompleted);
            Client1.GetPublicOfficialRecordCompleted +=
                new EventHandler<PublicOfficialSelectionService.GetPublicOfficialRecordCompletedEventArgs>(Client1_GetPublicOfficialRecordCompleted);
            Client1.GetPublicOfficialRecordAsync(OrgID, index * 20, index * 20 + 20, DateTime.Today.Year - nian.SelectedIndex, islock, ExamID);
        }
        #endregion

        private void ImageButton_Click(object sender, RoutedEventArgs e)
        {
            foreach (PublicOfficialSelectionService.PublicOfficialRecordModel i in (ObservableCollection<PublicOfficialSelectionService.PublicOfficialRecordModel>)DGRole.ItemsSource)
            {
                if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null) selectedempmodel.Add(i);
                if (i.IsSelected == false && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null)
                    selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
            }
            if (selectedempmodel.Count > 0)
            {
                if (selectedempmodel.Count > 1)
                {
                    SilverlightMessageBoxLibrary.Message.ErrorMessage("只能选择一个职位进行查看！");
                    return;
                }
                PublicOfficialRecordWindow view = new PublicOfficialRecordWindow(selectedempmodel[0].ID, (DateTime.Today.Year - nian.SelectedIndex).ToString());
                view.Nav = Nav;
                Nav.ShowNextPage(selectedempmodel[0].Duty + "-详细信息", view, this);
            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要查看的职位！");
        }
        private Stream ss = null;

        public ObservableCollection<PublicOfficialRecordModel> tempforall =
            new ObservableCollection<PublicOfficialRecordModel>();
        /// <summary>
        /// 数据表导出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOut_Click(object sender, RoutedEventArgs e)
        {
            //tempforall.Clear();
            //if (DGRole.ItemsSource != null)
            //{
            //    foreach (PublicOfficialSelectionService.PublicOfficialRecordModel i in (ObservableCollection<PublicOfficialSelectionService.PublicOfficialRecordModel>)DGRole.ItemsSource)
            //    {
            //        if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null) selectedempmodel.Add(i);
            //        if (i.IsSelected == false && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null)
            //            selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
            //    }
            //}
            //if (selectedempmodel.Count <= 0)
            //{
            //    SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要导出的数据！"); 
            //    return;
            //}
            //string ids = "";
            //foreach (var i in selectedempmodel)
            //{
            //    ids = ids + i.PublicOfficialSelectionID.ToString() + ",";
            //}
            var downLoad = new SaveFileDialog()
            {
                //Filter = "Excel files(2007~2010) (*.xlsx)|*.xlsx|Excel files(2003) (*.xls)|*.xls", //"Excel files (*.xlsx)|*.xlsx|(*.xls)|*.xls",
                Filter = "Excel files(2003) (*.xls)|*.xls",
            };
            if (downLoad.ShowDialog() == true)
            {
                ss = downLoad.OpenFile();
                PageInit();
                //Client1.GetPublicOfficialRecordAllForDaoChuCompleted += new EventHandler<PublicOfficialSelectionService.GetPublicOfficialRecordAllForDaoChuCompletedEventArgs>(Client1_GetPublicOfficialRecordAllForDaoChuCompleted);
                //Client1.GetPublicOfficialRecordAllForDaoChuAsync(ids.Substring(0,ids.Length - 1), ss);
            }
        }

        void Client1_GetPublicOfficialRecordAllForDaoChuCompleted(object sender, PublicOfficialSelectionService.GetPublicOfficialRecordAllForDaoChuCompletedEventArgs e)
        {
            ss = e.UserState as Stream;
            tempforall = e.Result;
            PageInit();
        }
        public void PageInit()
        {
            XlsDocument xls = new XlsDocument();
            XF xf = xls.NewXF();
            xf.HorizontalAlignment = HorizontalAlignments.Centered;
            xf.VerticalAlignment = VerticalAlignments.Centered;
            xf.UseBorder = true;
            xf.TopLineStyle = 1;
            xf.TopLineColor = org.in2bits.MyXls.Colors.Black;
            xf.BottomLineStyle = 1;
            xf.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            xf.LeftLineStyle = 1;
            xf.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            xf.RightLineStyle = 1;
            xf.RightLineColor = org.in2bits.MyXls.Colors.Black;
            XF xf1 = xls.NewXF();
            //xf1.UseBorder = true;
            //xf1.TopLineStyle = 1;
            //xf1.TopLineColor = org.in2bits.MyXls.Colors.Black;
            //xf1.BottomLineStyle = 1;
            //xf1.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            //xf1.LeftLineStyle = 1;
            //xf1.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            //xf1.RightLineStyle = 1;
            //xf1.RightLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.HorizontalAlignment = HorizontalAlignments.Centered;
            xf1.VerticalAlignment = VerticalAlignments.Centered;
            xf1.Font.Bold = true;
            xf1.Font.Height = 15 * 20;

            XF xf3 = xls.NewXF();
            xf3.UseBorder = true;
            xf3.TopLineStyle = 1;
            xf3.TopLineColor = org.in2bits.MyXls.Colors.Black;
            xf3.BottomLineStyle = 1;
            xf3.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            xf3.LeftLineStyle = 1;
            xf3.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            xf3.RightLineStyle = 1;
            xf3.RightLineColor = org.in2bits.MyXls.Colors.Black;
            xf3.HorizontalAlignment = HorizontalAlignments.Centered;
            xf3.VerticalAlignment = VerticalAlignments.Centered;
            xf3.Font.Bold = true;
            xf3.Font.Height = 12 * 20;
            Worksheet sheet1 = xls.Workbook.Worksheets.AddNamed("报名情况汇总表");
            sheet1.Cells.Merge(1, 1, 1, 9);
            sheet1.Cells.Add(1, 1, "徐汇区" + (DateTime.Today.Year - nian.SelectedIndex).ToString() + "年科级及科以下公务员" + tempforall[0].FaBuType + "报名情况汇总表", xf1);
            sheet1.Cells.Add(2, 1, "序号", xf3);
            sheet1.Cells.Add(2, 2, "报名单位", xf3);
            sheet1.Cells.Add(2, 3, "报名部门", xf3);
            sheet1.Cells.Add(2, 4, "报名科室", xf3);
            sheet1.Cells.Add(2, 5, "报名职位", xf3);
            sheet1.Cells.Add(2, 6, "报名人数", xf3);
            sheet1.Cells.Add(2, 7, "已审核人数", xf3);
            sheet1.Cells.Add(2, 8, "该职位通过人数", xf3);
            sheet1.Cells.Add(2, 9, "待审核人数", xf3);
            ColumnInfo colInfoxueli1 = new ColumnInfo(xls, sheet1);
            colInfoxueli1.Width = 40 * 256;
            colInfoxueli1.ColumnIndexStart = 2;
            colInfoxueli1.ColumnIndexEnd = 2;
            sheet1.AddColumnInfo(colInfoxueli1);
            ColumnInfo colInfoxueli3 = new ColumnInfo(xls, sheet1);
            colInfoxueli3.Width = 30 * 256;
            colInfoxueli3.ColumnIndexStart = 3;
            colInfoxueli3.ColumnIndexEnd = 3;
            sheet1.AddColumnInfo(colInfoxueli3);
            ColumnInfo colInfoxueli7 = new ColumnInfo(xls, sheet1);
            colInfoxueli7.Width = 15 * 256;
            colInfoxueli7.ColumnIndexStart = 7;
            colInfoxueli7.ColumnIndexEnd = 7;
            sheet1.AddColumnInfo(colInfoxueli7);
            ColumnInfo colInfoxueli6 = new ColumnInfo(xls, sheet1);
            colInfoxueli6.Width = 15 * 256;
            colInfoxueli6.ColumnIndexStart = 6;
            colInfoxueli6.ColumnIndexEnd = 6;
            sheet1.AddColumnInfo(colInfoxueli6);
            ColumnInfo colInfoxueli9 = new ColumnInfo(xls, sheet1);
            colInfoxueli9.Width = 15 * 256;
            colInfoxueli9.ColumnIndexStart = 9;
            colInfoxueli9.ColumnIndexEnd = 9;
            sheet1.AddColumnInfo(colInfoxueli9);
            ColumnInfo colInfoxueli8 = new ColumnInfo(xls, sheet1);
            colInfoxueli8.Width = 25 * 256;
            colInfoxueli8.ColumnIndexStart = 8;
            colInfoxueli8.ColumnIndexEnd = 8;
            sheet1.AddColumnInfo(colInfoxueli8);
            //填充内容    
            if (tempforall.Count > 0)
                for (int i = 0; i < tempforall.Count; i++)
                {
                    sheet1.Cells.Add(i + 3, 1, i + 1, xf);
                    if (tempforall[i].Department != null) sheet1.Cells.Add(i + 3, 2, tempforall[i].Department.ToString(), xf);
                    if (tempforall[i].Unit != null) sheet1.Cells.Add(i + 3, 3, tempforall[i].Unit.ToString(), xf);
                    if (tempforall[i].Duty != null) sheet1.Cells.Add(i + 3, 4, tempforall[i].Department_Duty.ToString(), xf);
                    if (tempforall[i].Duty != null) sheet1.Cells.Add(i + 3, 5, tempforall[i].Duty.ToString(), xf);
                    if (tempforall[i].BaoMingCount != null) sheet1.Cells.Add(i + 3, 6, tempforall[i].BaoMingCount.ToString(), xf);
                    if (tempforall[i].YiShenHeCount != null) sheet1.Cells.Add(i + 3, 7, tempforall[i].YiShenHeCount.ToString(), xf);
                    if (tempforall[i].GaiYiShenHeCount != null) sheet1.Cells.Add(i + 3, 8, tempforall[i].GaiYiShenHeCount.ToString(), xf);
                    if (tempforall[i].DaiShenHeCount != null) sheet1.Cells.Add(i + 3, 9, tempforall[i].DaiShenHeCount.ToString(), xf);

                }
            xls.Save(ss);
            ss.Close();
            ss.Dispose();
            SilverlightMessageBoxLibrary.Message.InfoMessage("导出成功！");
        }

        private void btnOut_Click1(object sender, RoutedEventArgs e)
        {
            var downLoad = new SaveFileDialog()
            {
                Filter = "Excel files(2003) (*.xls)|*.xls",
            };
            if (downLoad.ShowDialog() == true)
            {
                ss = downLoad.OpenFile();
                Client1.GetPublicOfficialRecordbyIDCompleted += new EventHandler<PublicOfficialSelectionService.GetPublicOfficialRecordbyIDCompletedEventArgs>(Client1_GetPublicOfficialRecordbyIDCompleted);
                Client1.GetPublicOfficialRecordbyIDAsync(0, ss);
            }
        }

        void Client1_GetPublicOfficialRecordbyIDCompleted(object sender, PublicOfficialSelectionService.GetPublicOfficialRecordbyIDCompletedEventArgs e)
        {
            ss = e.UserState as Stream;
            tempforall1 = e.Result;
            PageInit2();
        }
        /// <summary>
        /// 导出报名信息
        /// </summary>
        public void PageInit2()
        {
            XlsDocument xls = new XlsDocument();
            XF xf = xls.NewXF();
            xf.HorizontalAlignment = HorizontalAlignments.Centered;
            xf.VerticalAlignment = VerticalAlignments.Centered;
            xf.UseBorder = true;
            xf.TopLineStyle = 1;
            xf.TopLineColor = org.in2bits.MyXls.Colors.Black;
            xf.BottomLineStyle = 1;
            xf.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            xf.LeftLineStyle = 1;
            xf.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            xf.RightLineStyle = 1;
            xf.RightLineColor = org.in2bits.MyXls.Colors.Black;
            xf.Font.FontName = "宋体"; // 字体 
            xf.TextWrapRight = true;

            XF xf1 = xls.NewXF();
            xf1.UseBorder = true;
            xf1.TopLineStyle = 1;
            xf1.TopLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.BottomLineStyle = 1;
            xf1.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.LeftLineStyle = 1;
            xf1.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.RightLineStyle = 1;
            xf1.RightLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.HorizontalAlignment = HorizontalAlignments.Centered;
            xf1.VerticalAlignment = VerticalAlignments.Centered;
            xf1.Font.Bold = true;
            xf1.Font.Height = 15 * 20;

            XF xf2 = xls.NewXF();
            xf2.UseBorder = true;
            xf2.TopLineStyle = 1;
            xf2.TopLineColor = org.in2bits.MyXls.Colors.Black;
            xf2.BottomLineStyle = 1;
            xf2.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            xf2.LeftLineStyle = 1;
            xf2.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            xf2.RightLineStyle = 1;
            xf2.RightLineColor = org.in2bits.MyXls.Colors.Black;
            xf2.HorizontalAlignment = HorizontalAlignments.Centered;
            xf2.VerticalAlignment = VerticalAlignments.Centered;
            xf2.Font.Bold = true;
            xf2.Font.FontName = "黑体"; // 字体  
            xf2.Font.Height = 12 * 20;
            xf2.TextWrapRight = true;

            if (tempforall1.Count != 0)
            {
                Worksheet sheet1 = xls.Workbook.Worksheets.AddNamed("岗位报名信息汇总表");
                sheet1.Cells.Merge(1, 1, 1, 11);
                sheet1.Cells.Add(1, 1, "徐汇区" + (DateTime.Today.Year - nian.SelectedIndex).ToString() + "年科级及科以下公务员" + tempforall1[0].FaBuType + "岗位报名信息汇总表", xf1);
                sheet1.Cells.Add(2, 1, "序号", xf2);
                sheet1.Cells.Add(2, 2, "报名单位", xf2);
                sheet1.Cells.Add(2, 3, "报名部门", xf2);
                sheet1.Cells.Add(2, 4, "报名科室", xf2);
                sheet1.Cells.Add(2, 5, "报名职位", xf2);
                sheet1.Cells.Add(2, 6, "姓名", xf2);
                sheet1.Cells.Add(2, 7, "证件号", xf2);
                sheet1.Cells.Add(2, 8, "现工作部门", xf2);
                sheet1.Cells.Add(2, 9, "现科室", xf2);
                sheet1.Cells.Add(2, 10, "是否已审核", xf2);
                sheet1.Cells.Add(2, 11, "审核意见", xf2);
                ColumnInfo colInfoxueli1 = new ColumnInfo(xls, sheet1);
                colInfoxueli1.Width = 40 * 256;
                colInfoxueli1.ColumnIndexStart = 2;
                colInfoxueli1.ColumnIndexEnd = 2;
                sheet1.AddColumnInfo(colInfoxueli1);
                ColumnInfo colInfoxueli3 = new ColumnInfo(xls, sheet1);
                colInfoxueli3.Width = 30 * 256;
                colInfoxueli3.ColumnIndexStart = 3;
                colInfoxueli3.ColumnIndexEnd = 3;
                sheet1.AddColumnInfo(colInfoxueli3);
                ColumnInfo colInfoxueli9 = new ColumnInfo(xls, sheet1);
                colInfoxueli9.Width = 30 * 256;
                colInfoxueli9.ColumnIndexStart = 4;
                colInfoxueli9.ColumnIndexEnd = 4;
                sheet1.AddColumnInfo(colInfoxueli9);
                ColumnInfo colInfoxueli4 = new ColumnInfo(xls, sheet1);
                colInfoxueli4.Width = 30 * 256;
                colInfoxueli4.ColumnIndexStart = 6;
                colInfoxueli4.ColumnIndexEnd = 6;
                sheet1.AddColumnInfo(colInfoxueli4);
                ColumnInfo colInfoxueli8 = new ColumnInfo(xls, sheet1);
                colInfoxueli8.Width = 30 * 256;
                colInfoxueli8.ColumnIndexStart = 7;
                colInfoxueli8.ColumnIndexEnd = 7;
                sheet1.AddColumnInfo(colInfoxueli8);
                ColumnInfo colInfoxueli6 = new ColumnInfo(xls, sheet1);
                colInfoxueli6.Width = 40 * 256;
                colInfoxueli6.ColumnIndexStart = 8;
                colInfoxueli6.ColumnIndexEnd = 8;
                sheet1.AddColumnInfo(colInfoxueli6);
                ColumnInfo colInfoxueli7 = new ColumnInfo(xls, sheet1);
                colInfoxueli7.Width = 30 * 256;
                colInfoxueli7.ColumnIndexStart = 9;
                colInfoxueli7.ColumnIndexEnd = 9;
                sheet1.AddColumnInfo(colInfoxueli7);
                //填充内容    

                for (int i = 0; i < tempforall1.Count; i++)
                {
                    sheet1.Cells.Add(i + 3, 1, i + 1, xf);
                    sheet1.Cells.Add(i + 3, 2, "徐汇区", xf);
                    if (tempforall1[i].Unit != null) sheet1.Cells.Add(i + 3, 3, tempforall1[i].Unit.ToString(), xf);
                    else sheet1.Cells.Add(i + 3, 3, "", xf);
                    if (tempforall1[i].Department_Duty != null) sheet1.Cells.Add(i + 3, 4, tempforall1[i].Department_Duty.ToString(), xf);
                    else sheet1.Cells.Add(i + 3, 4, "", xf);
                    if (tempforall1[i].Duty != null) sheet1.Cells.Add(i + 3, 5, tempforall1[i].Duty.ToString(), xf);
                    else sheet1.Cells.Add(i + 3, 5, "", xf);
                    if (tempforall1[i].EmpName != null) sheet1.Cells.Add(i + 3, 6, tempforall1[i].EmpName.ToString(), xf);
                    else sheet1.Cells.Add(i + 3, 6, "", xf);
                    if (tempforall1[i].CardNo != null) sheet1.Cells.Add(i + 3, 7, tempforall1[i].CardNo.ToString(), xf);
                    else sheet1.Cells.Add(i + 3, 7, "", xf);
                    if (tempforall1[i].NowUnit != null) sheet1.Cells.Add(i + 3, 8, tempforall1[i].NowUnit.ToString(), xf);
                    else sheet1.Cells.Add(i + 3, 8, "", xf);
                    if (tempforall1[i].NowDuty != null) sheet1.Cells.Add(i + 3, 9, tempforall1[i].NowDuty.ToString(), xf);
                    else sheet1.Cells.Add(i + 3, 9, "", xf);
                    if (tempforall1[i].CheckState != null) sheet1.Cells.Add(i + 3, 10, tempforall1[i].CheckState.ToString(), xf);
                    else sheet1.Cells.Add(i + 3, 10, "", xf);
                    if (tempforall1[i].CheckMemo != null) sheet1.Cells.Add(i + 3, 11, tempforall1[i].CheckMemo, xf);
                    else sheet1.Cells.Add(i + 3, 11, "", xf);

                }

                sheet1.Cells.Merge(3, tempforall1.Count + 2, 2, 2);

                //int sint1 = 4;
                //int eint1 = 0;
                //for (int i = 0; i < tempforall1.Count - 1; i++)
                //{
                //    if (tempforall1[i].Unit == tempforall1[i + 1].Unit)
                //    {
                //        eint1 = i + 1 + 3;
                //        if (i == tempforall1.Count - 2)
                //        {
                //            sheet1.Cells.Merge(sint1, eint1, 3, 3);
                //        }
                //    }
                //    else
                //    {
                //        sheet1.Cells.Merge(sint1, eint1, 3, 3);
                //        sint1 = eint1 + 1;
                //        eint1 += 1;
                //    }
                //}
            }

            xls.Save(ss);
            ss.Close();
            ss.Dispose();
            SilverlightMessageBoxLibrary.Message.InfoMessage("导出成功！");
        }

        private void btnOut_Click2(object sender, RoutedEventArgs e)
        {
            var downLoad = new SaveFileDialog()
            {
                Filter = "Excel files(2003) (*.xls)|*.xls",
            };
            if (downLoad.ShowDialog() == true)
            {
                ss = downLoad.OpenFile();
                Client1.GetPublicOfficialCompleted += new EventHandler<GetPublicOfficialCompletedEventArgs>(Client1_GetPublicOfficialCompleted);
                Client1.GetPublicOfficialAsync(DateTime.Today.Year - nian.SelectedIndex, islock, ss);
            }
        }

        void Client1_GetPublicOfficialCompleted(object sender, GetPublicOfficialCompletedEventArgs e)
        {
            ss = e.UserState as Stream;
            tempforall1 = e.Result;
            PageInit1();
        }
        public ObservableCollection<PublicOfficialRecordModel> tempforall1 =
            new ObservableCollection<PublicOfficialRecordModel>();
        /// <summary>
        /// 导出审核通过信息
        /// </summary>
        public void PageInit1()
        {
            XlsDocument xls = new XlsDocument();
            XF xf = xls.NewXF();
            xf.HorizontalAlignment = HorizontalAlignments.Centered;
            xf.VerticalAlignment = VerticalAlignments.Centered;
            xf.UseBorder = true;
            xf.TopLineStyle = 1;
            xf.TopLineColor = org.in2bits.MyXls.Colors.Black;
            xf.BottomLineStyle = 1;
            xf.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            xf.LeftLineStyle = 1;
            xf.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            xf.RightLineStyle = 1;
            xf.RightLineColor = org.in2bits.MyXls.Colors.Black;
            xf.Font.FontName = "宋体"; // 字体 
            xf.TextWrapRight = true;

            XF xf1 = xls.NewXF();
            xf1.UseBorder = true;
            xf1.TopLineStyle = 1;
            xf1.TopLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.BottomLineStyle = 1;
            xf1.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.LeftLineStyle = 1;
            xf1.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.RightLineStyle = 1;
            xf1.RightLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.HorizontalAlignment = HorizontalAlignments.Centered;
            xf1.VerticalAlignment = VerticalAlignments.Centered;
            xf1.Font.Bold = true;
            xf1.Font.Height = 15 * 20;

            XF xf2 = xls.NewXF();
            xf2.UseBorder = true;
            xf2.TopLineStyle = 1;
            xf2.TopLineColor = org.in2bits.MyXls.Colors.Black;
            xf2.BottomLineStyle = 1;
            xf2.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            xf2.LeftLineStyle = 1;
            xf2.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            xf2.RightLineStyle = 1;
            xf2.RightLineColor = org.in2bits.MyXls.Colors.Black;
            xf2.HorizontalAlignment = HorizontalAlignments.Centered;
            xf2.VerticalAlignment = VerticalAlignments.Centered;
            xf2.Font.Bold = true;
            xf2.Font.FontName = "黑体"; // 字体  
            xf2.Font.Height = 12 * 20;
            xf2.TextWrapRight = true;

            if (tempforall1.Count != 0)
            {
            Worksheet sheet1 = xls.Workbook.Worksheets.AddNamed("岗位报名信息汇总表");
            sheet1.Cells.Merge(1, 1, 1, 29);
            sheet1.Cells.Add(1, 1, "徐汇区" + (DateTime.Today.Year - nian.SelectedIndex).ToString() + "年科级及科以下公务员" + tempforall1[0].FaBuType + "岗位审核通过人员汇总表", xf1);
            sheet1.Cells.Add(2, 1, "序号", xf2);
            sheet1.Cells.Add(2, 2, "报名单位", xf2);
            sheet1.Cells.Add(2, 3, "报名部门", xf2);
            sheet1.Cells.Add(2, 4, "报名科室", xf2);
            sheet1.Cells.Add(2, 5, "报名职位", xf2);
            sheet1.Cells.Add(2, 6, "姓名", xf2);
            sheet1.Cells.Add(2, 7, "证件号", xf2);
            sheet1.Cells.Add(2, 8, "现工作部门", xf2);
            sheet1.Cells.Add(2, 9, "现科室", xf2);
            sheet1.Cells.Add(2, 10, "现任职务层次", xf2);
            sheet1.Cells.Add(2, 11, "现任职务层次时间", xf2);

            sheet1.Cells.Add(2, 12, "职务属性", xf2);
            sheet1.Cells.Add(2, 13, "性别", xf2);
            sheet1.Cells.Add(2, 14, "出生日期", xf2);
            sheet1.Cells.Add(2, 15, "政治面貌", xf2);
            sheet1.Cells.Add(2, 16, "民族", xf2);
            sheet1.Cells.Add(2, 17, "毕业院校及专业", xf2);
            sheet1.Cells.Add(2, 18, "毕业院校及专业", xf2);
            sheet1.Cells.Add(2, 19, "毕业院校及专业", xf2);

            sheet1.Cells.Add(2, 20, "毕业院校及专业", xf2);
            sheet1.Cells.Add(2, 21, "毕业院校及专业", xf2);
            sheet1.Cells.Add(2, 22, "毕业院校及专业", xf2);
            sheet1.Cells.Add(2, 23, "学历", xf2);
            sheet1.Cells.Add(2, 24, "学位", xf2);
            sheet1.Cells.Add(2, 25, "联系方式/手机号码", xf2);
            sheet1.Cells.Add(2, 26, "电子邮箱", xf2);

            sheet1.Cells.Add(2, 27, "健康程度", xf2);
            sheet1.Cells.Add(2, 28, "婚姻状况", xf2);
            sheet1.Cells.Add(2, 29, "通讯地址", xf2);


            sheet1.Cells.Add(3, 17, "本科毕业院校", xf2);
            sheet1.Cells.Add(3, 18, "本科专业", xf2);
            sheet1.Cells.Add(3, 19, "硕士毕业院校", xf2);

            sheet1.Cells.Add(3, 20, "硕士专业", xf2);
            sheet1.Cells.Add(3, 21, "博士毕业院校", xf2);
            sheet1.Cells.Add(3, 22, "博士专业", xf2);
            sheet1.Cells.Merge(2, 3, 1, 1); sheet1.Cells.Merge(2, 3, 2, 2); sheet1.Cells.Merge(2, 3, 3, 3); sheet1.Cells.Merge(2, 3, 4, 4); sheet1.Cells.Merge(2, 3, 5, 5);
            sheet1.Cells.Merge(2, 3, 6, 6); sheet1.Cells.Merge(2, 3, 7, 7); sheet1.Cells.Merge(2, 3, 8, 8); sheet1.Cells.Merge(2, 3, 9, 9); sheet1.Cells.Merge(2, 3, 10, 10);
            sheet1.Cells.Merge(2, 3, 11, 11); sheet1.Cells.Merge(2, 3, 12, 12); sheet1.Cells.Merge(2, 3, 13, 13); sheet1.Cells.Merge(2, 3, 14, 14); sheet1.Cells.Merge(2, 3, 15, 15);
            sheet1.Cells.Merge(2, 2, 16, 21); sheet1.Cells.Merge(2, 3, 22, 22); sheet1.Cells.Merge(2, 3, 23, 23); sheet1.Cells.Merge(2, 3, 24, 24);
            sheet1.Cells.Merge(2, 3, 25, 25); sheet1.Cells.Merge(2, 3, 26, 26); sheet1.Cells.Merge(2, 3, 27, 27); sheet1.Cells.Merge(2, 3, 28, 28); ; sheet1.Cells.Merge(2, 3, 29, 29);
            ColumnInfo colInfoxueli1 = new ColumnInfo(xls, sheet1);
            colInfoxueli1.Width = 40 * 256;
            colInfoxueli1.ColumnIndexStart = 2;
            colInfoxueli1.ColumnIndexEnd = 2;
            sheet1.AddColumnInfo(colInfoxueli1);
            ColumnInfo colInfoxueli3 = new ColumnInfo(xls, sheet1);
            colInfoxueli3.Width = 30 * 256;
            colInfoxueli3.ColumnIndexStart = 3;
            colInfoxueli3.ColumnIndexEnd = 3;
            sheet1.AddColumnInfo(colInfoxueli3);
            ColumnInfo colInfoxueli9 = new ColumnInfo(xls, sheet1);
            colInfoxueli9.Width = 30 * 256;
            colInfoxueli9.ColumnIndexStart = 4;
            colInfoxueli9.ColumnIndexEnd = 4;
            sheet1.AddColumnInfo(colInfoxueli9);
            ColumnInfo colInfoxueli4 = new ColumnInfo(xls, sheet1);
            colInfoxueli4.Width = 30 * 256;
            colInfoxueli4.ColumnIndexStart = 6;
            colInfoxueli4.ColumnIndexEnd = 6;
            sheet1.AddColumnInfo(colInfoxueli4);
            ColumnInfo colInfoxueli8 = new ColumnInfo(xls, sheet1);
            colInfoxueli8.Width = 30 * 256;
            colInfoxueli8.ColumnIndexStart = 7;
            colInfoxueli8.ColumnIndexEnd = 7;
            sheet1.AddColumnInfo(colInfoxueli8);
            ColumnInfo colInfoxueli6 = new ColumnInfo(xls, sheet1);
            colInfoxueli6.Width = 40 * 256;
            colInfoxueli6.ColumnIndexStart = 8;
            colInfoxueli6.ColumnIndexEnd = 8;
            sheet1.AddColumnInfo(colInfoxueli6);
            ColumnInfo colInfoxueli7 = new ColumnInfo(xls, sheet1);
            colInfoxueli7.Width = 30 * 256;
            colInfoxueli7.ColumnIndexStart = 9;
            colInfoxueli7.ColumnIndexEnd = 9;
            sheet1.AddColumnInfo(colInfoxueli7);
            ColumnInfo colInfoxueli28 = new ColumnInfo(xls, sheet1);
            colInfoxueli28.Width = 30 * 256;
            colInfoxueli28.ColumnIndexStart = 29;
            colInfoxueli28.ColumnIndexEnd = 29;
            sheet1.AddColumnInfo(colInfoxueli28);
            //填充内容    
            
                for (int i = 0; i < tempforall1.Count; i++)
                {
                    sheet1.Cells.Add(i + 4, 1, i + 1, xf);
                    sheet1.Cells.Add(i + 4, 2, "徐汇区", xf);
                    if (tempforall1[i].Department != null) sheet1.Cells.Add(i + 4, 3, tempforall1[i].Department.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 3, "", xf);
                    if (tempforall1[i].Department_Duty != null) sheet1.Cells.Add(i + 4, 4, tempforall1[i].Department_Duty.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 4, "", xf);
                    if (tempforall1[i].Duty != null) sheet1.Cells.Add(i + 4, 5, tempforall1[i].Duty.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 5, "", xf);
                    if (tempforall1[i].EmpName != null) sheet1.Cells.Add(i + 4, 6, tempforall1[i].EmpName.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 6, "", xf);
                    if (tempforall1[i].CardNo != null) sheet1.Cells.Add(i + 4, 7, tempforall1[i].CardNo.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 7, "", xf);
                    if (tempforall1[i].OrgName != null) sheet1.Cells.Add(i + 4, 8, tempforall1[i].OrgName.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 8, "", xf);
                    if (tempforall1[i].PositionName != null) sheet1.Cells.Add(i + 4, 9, tempforall1[i].PositionName.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 9, "", xf);
                    if (tempforall1[i].DutyLevel != null) sheet1.Cells.Add(i + 4, 10, tempforall1[i].DutyLevel.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 10, "", xf);
                    if (tempforall1[i].OKDate != null) sheet1.Cells.Add(i + 4, 11, Convert.ToDateTime(tempforall1[i].OKDate).ToString("yyyy-MM-dd"), xf);
                    else sheet1.Cells.Add(i + 4, 11, "", xf);

                    if (tempforall1[i].DutyAttribute != null) sheet1.Cells.Add(i + 4, 12, tempforall1[i].DutyAttribute.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 12, "", xf);
                    if (tempforall1[i].Gender != null) sheet1.Cells.Add(i + 4, 13, tempforall1[i].Gender.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 13, "", xf);
                    if (tempforall1[i].Birthday != null) sheet1.Cells.Add(i + 4, 14, Convert.ToDateTime(tempforall1[i].Birthday).ToString("yyyy-MM-dd"), xf);
                    else sheet1.Cells.Add(i + 4, 14, "", xf);
                    if (tempforall1[i].Political != null) sheet1.Cells.Add(i + 4, 15, tempforall1[i].Political.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 15, "", xf);
                    if (tempforall1[i].Native != null) sheet1.Cells.Add(i + 4, 16, tempforall1[i].Native.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 16, "", xf);
                    if (tempforall1[i].BenKeSchool != null) sheet1.Cells.Add(i + 4, 17, tempforall1[i].BenKeSchool.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 17, "", xf);
                    if (tempforall1[i].BenKeProfessional != null) sheet1.Cells.Add(i + 4, 18, tempforall1[i].BenKeProfessional.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 18, "", xf);
                    if (tempforall1[i].ShuoShiSchool != null) sheet1.Cells.Add(i + 4, 19, tempforall1[i].ShuoShiSchool.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 19, "", xf);
                    if (tempforall1[i].ShuoShiProfessional != null) sheet1.Cells.Add(i + 4, 20, tempforall1[i].ShuoShiProfessional.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 20, "", xf);
                    if (tempforall1[i].BoShiSchool != null) sheet1.Cells.Add(i + 4, 21, tempforall1[i].BoShiSchool, xf);
                    else sheet1.Cells.Add(i + 4, 21, "", xf);

                    if (tempforall1[i].BoShiProfessional != null) sheet1.Cells.Add(i + 4, 22, tempforall1[i].BoShiProfessional, xf);
                    else sheet1.Cells.Add(i + 4, 22, "", xf);
                    if (tempforall1[i].FullEducationBg != null) sheet1.Cells.Add(i + 4, 23, tempforall1[i].FullEducationBg.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 23, "", xf);
                    if (tempforall1[i].FullDegree != null) sheet1.Cells.Add(i + 4, 24, tempforall1[i].FullDegree.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 24, "", xf);
                    if (tempforall1[i].Phone != null) sheet1.Cells.Add(i + 4, 25, tempforall1[i].Phone.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 25, "", xf);
                    if (tempforall1[i].Email != null) sheet1.Cells.Add(i + 4, 26, tempforall1[i].Email.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 26, "", xf);
                    if (tempforall1[i].Health != null) sheet1.Cells.Add(i + 4, 27, tempforall1[i].Health.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 27, "", xf);
                    if (tempforall1[i].Marriage != null) sheet1.Cells.Add(i + 4, 28, tempforall1[i].Marriage.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 28, "", xf);
                    if (tempforall1[i].HomeAddress != null) sheet1.Cells.Add(i + 4, 29, tempforall1[i].HomeAddress.ToString(), xf);
                    else sheet1.Cells.Add(i + 4, 29, "", xf);
                }

                sheet1.Cells.Merge(4, tempforall1.Count + 3, 2, 2);

                //int sint1 = 4;
                //int eint1 = 0;
                //for (int i = 0; i < tempforall1.Count - 1; i++)
                //{
                //    if (tempforall1[i].Unit == tempforall1[i + 1].Unit)
                //    {
                //        eint1 = i + 1 + 3;
                //        if (i == tempforall1.Count - 2)
                //        {
                //            sheet1.Cells.Merge(sint1, eint1, 3, 3);
                //        }
                //    }
                //    else
                //    {
                //        sheet1.Cells.Merge(sint1, eint1, 3, 3);
                //        sint1 = eint1 + 1;
                //        eint1 += 1;
                //    }
                //}
            }

            xls.Save(ss);
            ss.Close();
            ss.Dispose();
            SilverlightMessageBoxLibrary.Message.InfoMessage("导出成功！");
        }
    }
}
